﻿using System;
using Autodesk.Revit.DB;

namespace YArchitech.Plumbing.Model
{
	public class Parking
	{
		public Parking(Element e, double z, Document _doc, Transform t)
		{
			this.doc = _doc;
			this.ele = e;
			this.SetCenterAndRR(this.ele, z, t);
		}

		public void SetCenterAndRR(Element parking, double z, Transform t)
		{
			try
			{
				double num = 0.0;
				double num2 = 0.0;
				foreach (object obj in (parking as FamilyInstance).Symbol.Parameters)
				{
					Parameter parameter = (Parameter)obj;
					if (parameter.Definition.Name == "停车场长度")
					{
						num = Convert.ToDouble(parameter.AsValueString()) / 304.8;
					}
					if (parameter.Definition.Name == "停车场宽度")
					{
						num2 = Convert.ToDouble(parameter.AsValueString()) / 304.8;
					}
				}
				this.originLocation = (parking.Location as LocationPoint).Point;
				XYZ xyz = this.originLocation - new XYZ(0.0, 0.0, this.originLocation.Z);
				if (t != null)
				{
					this.originLocation = this.originLocation + t.Origin - new XYZ(0.0, 0.0, t.Origin.Z);
				}
				XYZ xyz2 = -(parking as FamilyInstance).FacingOrientation;
				XYZ xyz3 = (parking as FamilyInstance).HandOrientation;
				xyz2 = xyz2.Normalize();
				xyz3 = xyz3.Normalize();
				XYZ xyz4 = xyz + xyz2 * num;
				XYZ xyz5 = xyz + xyz3 * num2;
				XYZ xyz6 = xyz5 + xyz4 - xyz;
				if (t == null)
				{
					this.rr = new RectangleRange(xyz, xyz4, xyz6, xyz5);
				}
				else
				{
					XYZ xyz7 = t.Origin - new XYZ(0.0, 0.0, t.Origin.Z);
					this.rr = new RectangleRange(xyz + xyz7, xyz4 + xyz7, xyz6 + xyz7, xyz5 + xyz7);
				}
				if (t == null)
				{
					this.center = (xyz + xyz6) / 2.0;
				}
				else
				{
					this.center = (xyz + xyz6) / 2.0 + t.Origin - new XYZ(0.0, 0.0, t.Origin.Z);
				}
			}
			catch (Exception)
			{
			}
		}

		public XYZ center;

		public Element ele;

		public RectangleRange rr;

		public XYZ originLocation;

		public Document doc;
	}
}
